#pragma once
// MESSAGE XAP_MSG PACKING

#define MAVLINK_MSG_ID_XAP_MSG 20000


typedef struct __mavlink_xap_msg_t {
 uint32_t time_boot_ms; /*< [ms] Timestamp (milliseconds since system boot)*/
 int8_t field1; /*<   message field1 */
} mavlink_xap_msg_t;

#define MAVLINK_MSG_ID_XAP_MSG_LEN 5
#define MAVLINK_MSG_ID_XAP_MSG_MIN_LEN 5
#define MAVLINK_MSG_ID_20000_LEN 5
#define MAVLINK_MSG_ID_20000_MIN_LEN 5

#define MAVLINK_MSG_ID_XAP_MSG_CRC 188
#define MAVLINK_MSG_ID_20000_CRC 188



#if MAVLINK_COMMAND_24BIT
#define MAVLINK_MESSAGE_INFO_XAP_MSG { \
    20000, \
    "XAP_MSG", \
    2, \
    {  { "time_boot_ms", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_xap_msg_t, time_boot_ms) }, \
         { "field1", NULL, MAVLINK_TYPE_INT8_T, 0, 4, offsetof(mavlink_xap_msg_t, field1) }, \
         } \
}
#else
#define MAVLINK_MESSAGE_INFO_XAP_MSG { \
    "XAP_MSG", \
    2, \
    {  { "time_boot_ms", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_xap_msg_t, time_boot_ms) }, \
         { "field1", NULL, MAVLINK_TYPE_INT8_T, 0, 4, offsetof(mavlink_xap_msg_t, field1) }, \
         } \
}
#endif

/**
 * @brief Pack a xap_msg message
 * @param system_id ID of this system
 * @param component_id ID of this component (e.g. 200 for IMU)
 * @param msg The MAVLink message to compress the data into
 *
 * @param time_boot_ms [ms] Timestamp (milliseconds since system boot)
 * @param field1   message field1 
 * @return length of the message in bytes (excluding serial stream start sign)
 */
static inline uint16_t mavlink_msg_xap_msg_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
                               uint32_t time_boot_ms, int8_t field1)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
    char buf[MAVLINK_MSG_ID_XAP_MSG_LEN];
    _mav_put_uint32_t(buf, 0, time_boot_ms);
    _mav_put_int8_t(buf, 4, field1);

        memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_XAP_MSG_LEN);
#else
    mavlink_xap_msg_t packet;
    packet.time_boot_ms = time_boot_ms;
    packet.field1 = field1;

        memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_XAP_MSG_LEN);
#endif

    msg->msgid = MAVLINK_MSG_ID_XAP_MSG;
    return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_XAP_MSG_MIN_LEN, MAVLINK_MSG_ID_XAP_MSG_LEN, MAVLINK_MSG_ID_XAP_MSG_CRC);
}

/**
 * @brief Pack a xap_msg message on a channel
 * @param system_id ID of this system
 * @param component_id ID of this component (e.g. 200 for IMU)
 * @param chan The MAVLink channel this message will be sent over
 * @param msg The MAVLink message to compress the data into
 * @param time_boot_ms [ms] Timestamp (milliseconds since system boot)
 * @param field1   message field1 
 * @return length of the message in bytes (excluding serial stream start sign)
 */
static inline uint16_t mavlink_msg_xap_msg_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
                               mavlink_message_t* msg,
                                   uint32_t time_boot_ms,int8_t field1)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
    char buf[MAVLINK_MSG_ID_XAP_MSG_LEN];
    _mav_put_uint32_t(buf, 0, time_boot_ms);
    _mav_put_int8_t(buf, 4, field1);

        memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_XAP_MSG_LEN);
#else
    mavlink_xap_msg_t packet;
    packet.time_boot_ms = time_boot_ms;
    packet.field1 = field1;

        memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_XAP_MSG_LEN);
#endif

    msg->msgid = MAVLINK_MSG_ID_XAP_MSG;
    return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_XAP_MSG_MIN_LEN, MAVLINK_MSG_ID_XAP_MSG_LEN, MAVLINK_MSG_ID_XAP_MSG_CRC);
}

/**
 * @brief Encode a xap_msg struct
 *
 * @param system_id ID of this system
 * @param component_id ID of this component (e.g. 200 for IMU)
 * @param msg The MAVLink message to compress the data into
 * @param xap_msg C-struct to read the message contents from
 */
static inline uint16_t mavlink_msg_xap_msg_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_xap_msg_t* xap_msg)
{
    return mavlink_msg_xap_msg_pack(system_id, component_id, msg, xap_msg->time_boot_ms, xap_msg->field1);
}

/**
 * @brief Encode a xap_msg struct on a channel
 *
 * @param system_id ID of this system
 * @param component_id ID of this component (e.g. 200 for IMU)
 * @param chan The MAVLink channel this message will be sent over
 * @param msg The MAVLink message to compress the data into
 * @param xap_msg C-struct to read the message contents from
 */
static inline uint16_t mavlink_msg_xap_msg_encode_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, const mavlink_xap_msg_t* xap_msg)
{
    return mavlink_msg_xap_msg_pack_chan(system_id, component_id, chan, msg, xap_msg->time_boot_ms, xap_msg->field1);
}

/**
 * @brief Send a xap_msg message
 * @param chan MAVLink channel to send the message
 *
 * @param time_boot_ms [ms] Timestamp (milliseconds since system boot)
 * @param field1   message field1 
 */
#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS

static inline void mavlink_msg_xap_msg_send(mavlink_channel_t chan, uint32_t time_boot_ms, int8_t field1)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
    char buf[MAVLINK_MSG_ID_XAP_MSG_LEN];
    _mav_put_uint32_t(buf, 0, time_boot_ms);
    _mav_put_int8_t(buf, 4, field1);

    _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_XAP_MSG, buf, MAVLINK_MSG_ID_XAP_MSG_MIN_LEN, MAVLINK_MSG_ID_XAP_MSG_LEN, MAVLINK_MSG_ID_XAP_MSG_CRC);
#else
    mavlink_xap_msg_t packet;
    packet.time_boot_ms = time_boot_ms;
    packet.field1 = field1;

    _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_XAP_MSG, (const char *)&packet, MAVLINK_MSG_ID_XAP_MSG_MIN_LEN, MAVLINK_MSG_ID_XAP_MSG_LEN, MAVLINK_MSG_ID_XAP_MSG_CRC);
#endif
}

/**
 * @brief Send a xap_msg message
 * @param chan MAVLink channel to send the message
 * @param struct The MAVLink struct to serialize
 */
static inline void mavlink_msg_xap_msg_send_struct(mavlink_channel_t chan, const mavlink_xap_msg_t* xap_msg)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
    mavlink_msg_xap_msg_send(chan, xap_msg->time_boot_ms, xap_msg->field1);
#else
    _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_XAP_MSG, (const char *)xap_msg, MAVLINK_MSG_ID_XAP_MSG_MIN_LEN, MAVLINK_MSG_ID_XAP_MSG_LEN, MAVLINK_MSG_ID_XAP_MSG_CRC);
#endif
}

#if MAVLINK_MSG_ID_XAP_MSG_LEN <= MAVLINK_MAX_PAYLOAD_LEN
/*
  This varient of _send() can be used to save stack space by re-using
  memory from the receive buffer.  The caller provides a
  mavlink_message_t which is the size of a full mavlink message. This
  is usually the receive buffer for the channel, and allows a reply to an
  incoming message with minimum stack space usage.
 */
static inline void mavlink_msg_xap_msg_send_buf(mavlink_message_t *msgbuf, mavlink_channel_t chan,  uint32_t time_boot_ms, int8_t field1)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
    char *buf = (char *)msgbuf;
    _mav_put_uint32_t(buf, 0, time_boot_ms);
    _mav_put_int8_t(buf, 4, field1);

    _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_XAP_MSG, buf, MAVLINK_MSG_ID_XAP_MSG_MIN_LEN, MAVLINK_MSG_ID_XAP_MSG_LEN, MAVLINK_MSG_ID_XAP_MSG_CRC);
#else
    mavlink_xap_msg_t *packet = (mavlink_xap_msg_t *)msgbuf;
    packet->time_boot_ms = time_boot_ms;
    packet->field1 = field1;

    _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_XAP_MSG, (const char *)packet, MAVLINK_MSG_ID_XAP_MSG_MIN_LEN, MAVLINK_MSG_ID_XAP_MSG_LEN, MAVLINK_MSG_ID_XAP_MSG_CRC);
#endif
}
#endif

#endif

// MESSAGE XAP_MSG UNPACKING


/**
 * @brief Get field time_boot_ms from xap_msg message
 *
 * @return [ms] Timestamp (milliseconds since system boot)
 */
static inline uint32_t mavlink_msg_xap_msg_get_time_boot_ms(const mavlink_message_t* msg)
{
    return _MAV_RETURN_uint32_t(msg,  0);
}

/**
 * @brief Get field field1 from xap_msg message
 *
 * @return   message field1 
 */
static inline int8_t mavlink_msg_xap_msg_get_field1(const mavlink_message_t* msg)
{
    return _MAV_RETURN_int8_t(msg,  4);
}

/**
 * @brief Decode a xap_msg message into a struct
 *
 * @param msg The message to decode
 * @param xap_msg C-struct to decode the message contents into
 */
static inline void mavlink_msg_xap_msg_decode(const mavlink_message_t* msg, mavlink_xap_msg_t* xap_msg)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
    xap_msg->time_boot_ms = mavlink_msg_xap_msg_get_time_boot_ms(msg);
    xap_msg->field1 = mavlink_msg_xap_msg_get_field1(msg);
#else
        uint8_t len = msg->len < MAVLINK_MSG_ID_XAP_MSG_LEN? msg->len : MAVLINK_MSG_ID_XAP_MSG_LEN;
        memset(xap_msg, 0, MAVLINK_MSG_ID_XAP_MSG_LEN);
    memcpy(xap_msg, _MAV_PAYLOAD(msg), len);
#endif
}
